import prompt from '@system.prompt';

export default {
    data: {
        title: "",
        topTabSelected: 2,
        bottomTabSelected: 0,
        playerIndex: 0,
        isPlaying: true,
        duration: 0,
        timeupdatetime: 0,
        isRestore: false,
        isCompleteContinuation: false,
        //播放网络视频的时候的地址
        /* list: [{
                   videoPath: "http://122.112.245.136:5555/public/home/video/video0.mp4"
               }
        , {
                   videoPath: "http://122.112.245.136:5555/public/home/video/video1.mp4"
               }
        , {
                   videoPath: "http://122.112.245.136:5555/public/home/video/video2.mp4"
               }
        ]*/
        list: [{
                   videoPath: "/common/video/video0.mp4"
               }
        , {
                   videoPath: "/common/video/video1.mp4"
               }
        , {
                   videoPath: "/common/video/video2.mp4"
               }
        ]
    },
    onInit() {
        this.title = this.$t('strings.world');
    },
    topTabClick(i) {
        this.topTabSelected = i;
    },
    bottomTabClick(i) {
        this.bottomTabSelected = i;
    },
    changeVideo(obj) {
        this.$element(`playerId${this.playerIndex}`).pause();
        this.playerIndex = obj.index;
        console.info("playerIndex=" + this.playerIndex);
        this.$element(`playerId${this.playerIndex}`).start();
    },
    preparedCallback: function (e) {
        this.event = '视频连接成功';
        this.duration = e.duration;
        this.$element(`playerId${this.playerIndex}`).start();
    },
    startCallback: function () {
        console.info('视频开始播放')
        this.event = '视频开始播放';
        this.isPlaying = true;
    },
    pauseCallback: function () {
        this.event = '视频暂停播放';
        this.isPlaying = false;
    },
    finishCallback: function () {
        this.event = '视频播放结束';
    },
    errorCallback: function () {
        this.event = '视频播放错误';
    },

    timeupdateCallback: function (e) {
        this.timeupdatetime = e.currenttime;
    },
    changePlayeStatus: function () {
        if (this.isPlaying) {
            this.$element(`playerId${this.playerIndex}`).pause();
            this.isPlaying = false;
        } else {
            this.$element(`playerId${this.playerIndex}`).start();
            this.isPlaying = true;
        }
    },
    change_fullscreenchange: function () { //全屏
        if (!this.isfullscreenchange) {
            this.$element(`playerId${this.playerIndex}`).requestFullscreen({
                screenOrientation: 'default'
            });
            this.isfullscreenchange = true;
        } else {
            this.$element(`playerId${this.playerIndex}`).exitFullscreen();
            this.isfullscreenchange = false;
        }
    },

    async transfer() {
        console.info("transfer")
        await FeatureAbility.continueAbility();
    },

    forward() {
        prompt.showToast(
            {
                message: '分享功能待开发'
            }
        )
    },
    collection() {
        prompt.showToast(
            {
                message: '收藏功能待开发'
            }
        )
    },

    onSaveData(saveData) { // 数据保存到savedData中进行迁移。
        console.info("onSaveData")
        var data = {
            remoteTimeupdatetime: this.timeupdatetime,
            remotePlayerIndex: this.playerIndex
        };
        Object.assign(saveData, data)
    },
    onRestoreData(restoreData) { // 收到迁移数据，恢复。
        // 收到迁移数据，恢复。
        this.isRestore = true;
        console.info('==== onRestoreData ' + JSON.stringify(restoreData))
        this.timeupdatetime = restoreData.remoteTimeupdatetime
        this.playerIndex = restoreData.remotePlayerIndex
    },
    onCompleteContinuation(code) { //迁移完成
        console.info("onCompleteContinuation===" + code)
        this.isCompleteContinuation = true
    },
    onStartContinuation() { //迁移开始
        console.info("onStartContinuation")
        return true;
    }
}
